package com.dream.wukong.zipkin;

import com.dream.wukong.zipkin.properties.HiKariCPProperties;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import zipkin.server.EnableZipkinServer;
import zipkin.storage.mysql.MySQLStorage;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 19:38 2018/9/6.
 * @Modified:
 */

@SpringBootApplication
@EnableZipkinServer
@EnableEurekaClient
public class ZipkinApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZipkinApplication.class, args);
    }


    @Autowired
    HiKariCPProperties hiKariCPProperties;


    private HikariDataSource coreDataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        hiKariCPProperties.config(dataSource);
        return dataSource;
    }

    @Bean
//    @ConditionalOnProperty(prefix = "hollybeacons.system", name = "muti-datasource-open", havingValue = "false")
    public HikariDataSource singleDatasource() {
        return coreDataSource();
    }

    @Bean
    public MySQLStorage mySQLStorage(@Qualifier("singleDatasource") HikariDataSource zipkinDatasource) {
        return MySQLStorage.builder().datasource(zipkinDatasource).executor(Runnable::run).build();
    }


}
